﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JtextEpicsInterface
{
    /// <summary>
    /// Useed to handle when the driver has something to hand over to the server
    /// <seealso cref="IEJDriver"/>
    /// </summary>
    /// <param name="MyMessage">My message.</param>
    public delegate void SendToEJServerHandler(byte[] MyMessage);

    /// <summary>
    /// handle this driver crash evnet
    /// </summary>
    public delegate void DriverCrashHandler();  //when driver crash this happens

    /// <summary>
    /// if you are making a driver for the EpicsJacket ,implement this interface
    /// </summary>
    public interface  IEJDriver
    {
        //all the epics jacket driver should inmplement this interface
        /// <summary>
        /// Gets the name of the driver.Use hardCode.
        /// </summary>
        /// <value>
        /// The name of the driver.
        /// </value>
        string DriverName { get; }
        /// <summary>
        /// Occurs when [on send to EJ server].
        /// <para>When the driver has the message, rais this to hand it over to the EJServer</para>
        /// </summary>
        event SendToEJServerHandler OnSendToEJServer;
        
        /// <summary>
        /// Occurs when [on driver crash].
        /// <para>when you sence the driver or the hardware has crashed,rais this event</para>
        /// </summary>
        event DriverCrashHandler OnDriverCrash;

        /// <summary>
        /// Sets the driver.
        /// <para>this when config the driver</para>
        /// </summary>
        /// <param name="isByte">if set to <c>true</c>then the message [is byte].</param>
        /// <param name="len">The len of the message.</param>
        /// <param name="end">The ending mark of this message,only byte is allowed,if len is not 0 the it's not used</param>
        /// <param name="IniObj">The ini obj.the object to config the driver ususlly a string, contain the port number and ect</param>
        void SetDriver(bool isByte, int len, byte end, object IniObj);  //set the driver config
        /// <summary>
        /// Inis the driver.let the driver start to work
        /// <para>make sure you throw a exception ,if the driver is not work</para>
        /// </summary>
        void IniDriver();    //initialize the driver and start the listenner
        /// <summary>
        /// Stops the driver.
        /// </summary>
        void StopDriver();   //the oppsite of iniDriver
        /// <summary>
        /// Send_msgs the specified message string.used when using string message.
        /// </summary>
        /// <param name="message_str">The message string.</param>
        /// <returns></returns>
        int Send_msg(string message_str);      //send out a string message
        /// <summary>
        /// Send_msgs the specified message byte[].used when using Byte message
        /// </summary>
        /// <param name="message_byte">The message byte[].</param>
        /// <returns></returns>
        int Send_msg(byte[] message_byte);       //send out a byte message
    }

    /// <summary>
    /// if you are making a plugin for EpicsJacket,implement this interface.
    /// </summary>
    public interface IEJPlugIn
    {
        /// <summary>
        /// Gets the name of the plugin.
        /// </summary>
        /// <value>
        /// The name of the plugin.
        /// </value>
        string PluginName { get; }
        /// <summary>
        /// Procs the out message.
        /// <para>process the message that is sending out to meet the needs of the device</para>
        /// </summary>
        /// <param name="message_str">The message string.</param>
        /// <returns>the message</returns>
        string ProcOut(string message_str);
       
        /// <summary>
        /// Procs the out message.
        /// <para>process the message that is sending out to meet the needs of the device</para>
        /// </summary>
        /// <param name="message_byte">The message byte[].</param>
        /// <returns>the message</returns>
        byte[] ProcOut(byte[] message_byte);
        /// <summary>
        /// Procs the incoming messagehtath is from the device to meet the format of the EpicsJacket.
        /// </summary>
        /// <param name="message_byte">The message byte.becourse all message send up is treated as byte[]</param>
        /// <param name="IsByte">if set to <c>true</c> [is byte].if not youneed to change in to string and modify it then change back to byte[]</param>
        /// <param name="ToWho">To who.the server will tell you if this is send to scanner of to reply to the client.</param>
        /// <returns></returns>
        byte[] ProcIn(byte[] message_byte,bool IsByte,int ToWho); //2 is to messager,3 is to scanner
        /// <summary>
        /// Initialize the plug in.use config file to config it.
        /// </summary>
        void iniPlugIn();
    }


}
